<?php

namespace app\commands;

use app\models\CardBill;
use app\models\UserBill;
use yii\console\Controller;
use yii\db\Expression;

class TestController extends Controller
{
    public function actionIndex()
    {
        $month = '201904';
        $list = CardBill::find()
            ->andWhere(['month' => $month])
            ->asArray()
            ->select([
                'user_id' => 'user_id',
                'package_id' => 'package_id',
                'amount' => new Expression('count(0)'),
                'money' => new Expression('sum(money)'),
            ])
            ->groupBy('user_id, package_id')
            ->createCommand()->rawSql;
        print_r($list);
    }
}